package com.dlb.andorid.presenter;

import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.AddressRetrieval;
import com.dlb.andorid.bean.ArgMerchantReg;
import com.dlb.andorid.bean.MerchantType;
import com.dlb.andorid.bean.Province;

import java.util.HashMap;
import java.util.List;

public class ShrzPresenter extends XPresenter {

	private XContract.IShrzView iView;

	public ShrzPresenter(XContract.IShrzView iView) {
		super(iView);
		this.iView = iView;
	}

	public void getMerchantType() {
		mModel.getMerchantType();
	}

	public void getCity() {
		mModel.getAddressCity();
	}

	public void getAddressRetrieval(long province_id, long city_id, long area_id, String keyword) {
		mModel.getAddressRetrieval(province_id, city_id, area_id, keyword);
	}

	public void getCode(String phone, int ctype) {
		mModel.getCode(phone, ctype);
	}

	public void regMerchant(ArgMerchantReg arg){
		mModel.getMerchantReg(arg);
	}

	public void regRider(ArgMerchantReg arg){
		mModel.getRiderReg(arg);
	}

	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);

		switch (vocational_id) {
			case XAPI.GET_MERCHANT_TYPE:
				iView.getMerchantTypeListSuccess(((XServerMsg<List<MerchantType>>) data).getData());
				break;
			case XAPI.GET_ADDRESS_CITYS_VOCATIONAL_ID:
				iView.getAddressCitySuccess(((XServerMsg<List<Province>>) data).getData());
				break;
			case XAPI.GET_ADDRESS_RETRIEVAL_VOCATIONAL_ID:
				iView.getAddressRetrievalSuccess(((XServerMsg<List<AddressRetrieval>>) data).getData());
				break;
			case XAPI.GET_CODE_VOCATIONAL_ID:
				iView.getCodeSuccess(((XServerMsg) data).getMsg());
				break;
			case XAPI.GET_MERCHANT_REG:
				iView.regMerchantSuccess(((XServerMsg) data));
				break;
			case XAPI.GET_RIDER_REG:
				iView.regMerchantSuccess(((XServerMsg) data));
				break;
		}
	}
}
